package com.yishusmt.wechatapi.wechatdev.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author zhangyi
 * @date 2018/9/1 18:16
 */

public class CheckInputUtil {

    public static final String EMAIL_PANDUAN = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
    public static final String PHONE_PANDUAN = "^(((13[0-9])|(15([0-3]|[5-9]))|(18[0,5-9])|(17[0-9]))\\d{8})|(0\\d{2}-\\d{8})|(0\\d{3}-\\d{7})$";

    /**
     * 验证邮箱
     *
     * @param email
     * @return
     */
    public static boolean checkEmail(String email) {
        boolean flag = false;
        try {
            Pattern regex = Pattern.compile(EMAIL_PANDUAN);
            Matcher matcher = regex.matcher(email);
            flag = matcher.matches();
        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }

    /**
     * 验证手机号
     *
     * @param mobileNumber
     * @return
     */
    public static boolean checkMobileNumber(String mobileNumber) {
        boolean flag = false;
        try {
            Pattern regex = Pattern.compile(PHONE_PANDUAN);
            Matcher matcher = regex.matcher(mobileNumber);
            flag = matcher.matches();
        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }


}
